﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AdminDorList1 : System.Web.UI.Page
{
    string ID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        int Autoid = Convert.ToInt32(Request.QueryString["Dorid"]);
        string sql = string.Format("select * from Doctor where AutoID={0}", Autoid);
        SqlDataReader re = DBHelper.GetDataReader(sql);
        while (re.Read())
        {
            ID = re["ID"].ToString();
            this.LblID.Text = re["ID"].ToString();
            this.LblName.Text = re["Name"].ToString();
            this.LblIDCard.Text = re["IDCard"].ToString();
            this.TxtPin.Text = re["Position"].ToString();
            this.TxtDet.Text = re["Department"].ToString();
            this.TxtPhone.Text = re["Phone"].ToString();
            this.TxtIntroduction.Text = re["Introduction"].ToString();
            this.TxtAddress.Text = re["Address"].ToString();
        }
        re.Close();
        this.Image1.ImageUrl = string.Format("~/image/Photo/{0}.png", ID);
    }

    protected void BtnUpdata_Click(object sender, EventArgs e)
    {
        int Autoid = Convert.ToInt32(Request.QueryString["Dorid"]);
        string sql = string.Format("update Doctor set Position='{0}',Department='{1}',Phone='{2}',Address='{3}',Introduction='{4}' where AutoID={5}", this.TxtPin.Text, this.TxtDet.Text, this.TxtPhone.Text, this.TxtAddress.Text, this.TxtIntroduction.Text, Autoid);
        DBHelper.GetNonQuery(sql);
        Response.Write("<script> alert('信息更改成功！')</script>");
        Bind();
    }

    protected void BtnDel_Click(object sender, EventArgs e)
    {
        int Autoid = Convert.ToInt32(Request.QueryString["Dorid"]);
        string delsql = string.Format("delete from Doctor where AutoID={0}", Autoid);
        DBHelper.GetNonQuery(delsql);
        Response.Write("<script> alert('删除成功！')</script>");
        Response.Redirect("AdminDor.aspx");
    }
}